package com.example.w.common.dto;

import com.example.w.common.pojo.Order;
import com.example.w.common.pojo.OrderItem;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

@Data
public class OrderAddDTO {

    /**
     * 桌子id
     */
    private Integer tableId;

    /**
     * 添加的菜单项
     */
    private List<OrderItemAddDTO> orderItemList;

    /**
     * 转换为order
     */
    public Order convertToOrder() {
        Order order = new Order();
        List<OrderItem> itemList = new ArrayList<>();
        OrderItem item;
        //复制订单主体信息
        BeanUtils.copyProperties(this, order);
        //复制订单项信息
        for (OrderItemAddDTO itemDTO: orderItemList) {
            item = new OrderItem();
            BeanUtils.copyProperties(itemDTO, item);
            itemList.add(item);
        }
        order.setOrderItemList(itemList);
        return order;
    }

}
